local socket = require("socket")
local port = 6666


ctrlSocket = socket.connect4("127.0.0.1",port)


if ctrlSocket == nil then
    Isaac.ConsoleOutput("Isaac-dm:Can't connect to controller.")
    return
end

ctrlSocket:settimeout(5000)
if "Isaac" ~= ctrlSocket:receive('*l') then
    Isaac.ConsoleOutput("Isaac-dm:Can't connect to controller(protcol not match).")
    return
end

ctrlSocket:settimeout(0)
ctrlSocket:send("Isaac\n")

local IsaacDm = RegisterMod("IsaacDm", 1)

-- print=function(s)Isaac.ConsoleOutput(tostring(s))end

function IsaacDm:Update()
    local cmd = ctrlSocket:receive('*l')
    if cmd ~= nil then
        Isaac.ConsoleOutput(cmd .. "\n")
        Isaac.ExecuteCommand(cmd)
    end
end

IsaacDm:AddCallback(ModCallbacks.MC_POST_UPDATE,IsaacDm.Update)
